/**
 * Home 有关的API请求
 */
import request from "../../utils/request";


/**
 * 修改用户所属的学校
 * @param {String} open_id 用户ID
 * @param {String} school_id 新的学校ID
 * @returns Promise
 */
export function updateSchoolInfo(open_id, school_id) {
  return request({
    url: `/user/updateSelectSchool`,
    method: 'PUT',
    data: {
      open_id,
      school_id
    }
  })
}

/**
 * 获取picker学校选择器有关的数据
 * @returns Promise
 */
export function getPickerDatas() {
  return request({
    url: `/user/getPickerDatas`,
    method: 'GET'
  })
}

/**
 * 获取用户已经选择的学校的信息
 * @param {String} userId 用户ID
 * @returns Promise
 */
export function getUserSelectSchoolInfo(userId) {
  return request({
    url: `/home/getUserSelectSchoolInfo/${userId}`,
    method: 'GET'
  })
}

/**
 * 获取学校信息
 * @param {String} school_id 
 * @returns 
 */
export function getSchoolInfo(school_id){
  return request({
    url:`/user/getSelectSchoolInfo/${school_id}`,
    method:'GET'
  })
}

/**
 * 获取订单列表
 * @param {String} open_id 用户ID
 * @param {Number} page 页号
 * @param {number} limit 每页条目数量
 * @returns Promise
 */
export function getOrders(open_id, page, limit) {
  return request({
    url: `/user/getSimpleOrders/${open_id}?page=${page}&limit=${limit}`,
    method: 'GET'
  })
}

/**
 * 根据订单ID获取订单详情
 * @param {String} order_id 
 * @returns Promise
 */
export function getOrderDetail(order_id) {
  return request({
    url: `/user/getDetailOrder/${order_id}`,
    method: 'GET'
  })
}

/**
 * 获取收货地址列表
 * @param {String} open_id 
 * @returns Promise
 */
export function getAddressList(open_id,page,limit) {
  return request({
    url:`/user/getAddress/${open_id}?page=${page}&limit=${limit}`,
    method:'GET'
  })
}

/**
 * 新增收货地址
 * @param {String} open_id 
 * @param {Object} data 
 * @returns Promise
 */
export function increaseAddress(open_id,data){
  return request({
    url:`/user/increaseAddress/${open_id}`,
    method:'POST',
    data
  })
}

/**
 * 更新地址信息
 * @param {String} address_id 
 * @param {Object} data 
 * @returns Promise
 */
export function updateAddress(address_id,data){
  return request({
    url:`/user/updateAddress/${address_id}`,
    method:'PUT',
    data
  })
}

/**
 * 删除地址信息
 * @param {String} address_id 
 * @returns 
 */
export function deleteAddress(address_id){
  return request({
    url:`/user/deleteAddress/${address_id}`,
    method:'DELETE'
  })
}

/**
 * 获取地址信息
 * @param {String} address_id 
 * @returns Promise
 */
export function getAddressDetail(address_id){
  return request({
    url:`/user/getAddressDetail/${address_id}`,
    method:'GET'
  })
}